package com.loriot.common.corporate_flight_bookings_1109;

/**
 * @Title: pointsThatIntersectWithCars_2848
 * @Package: com.loriot.common
 * @Description:
 * @Author: zzy boy
 * @Date: 2025/10/21 10:36
 * @Version: 0.0.1-alpha
 */

public class Main {
    class Solution {
        public int[] corpFlightBookings(int[][] bookings, int n) {
            int[] differ = new int[n+1];
            for(int[] item:bookings){
                differ[item[0]-1] += item[2];
                differ[item[1]]-=item[2];
            }
            int[] rst = new int[n];
            rst[0] =differ[0];
            for(int i=1;i<rst.length;i++){
                rst[i] = rst[i-1] + differ[i];
            }
            return rst;
        }
    }

    class Solution2 {
        public int[] corpFlightBookings(int[][] bookings, int n) {
            int[] differAndrst = new int[n];
            for(int[] item:bookings){
                differAndrst[item[0]-1] += item[2];
                // 如果是最后一位
                if(item[1]==n){
                    continue;
                }
                differAndrst[item[1]]-=item[2];
            }
            for(int i=1;i<n;i++){
                differAndrst[i] += differAndrst[i-1];
            }
            return differAndrst;
        }
    }
}
